Skip to content

fix(editor): deduplicate blank tab indexes to fix incorrect new docum…#474

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
pppanghu77:release/eagle
Jun 9, 2026
Merged

fix(editor): deduplicate blank tab indexes to fix incorrect new docum…#474
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
pppanghu77:release/eagle

Conversation

@pppanghu77

Copy link
Copy Markdown
Contributor

…ent naming

  • Add std::unique + erase after sorting in getBlankFileIndex() to remove duplicate index numbers
  • Prevent newly created documents from being stuck with the same "Untitled N" name when tabs with duplicate titles are dragged between windows

修复(editor): 对空白标签索引去重以修复新文档命名错误

  • 在 getBlankFileIndex() 的排序后增加 std::unique + erase 去除重复的索引编号
  • 修复跨窗口拖入同名"未命名文档"标签后,新建文档名称始终为同一编号的问题

Log: 修复跨窗口拖拽标签导致新文档命名计数器异常的 bug
Bug: https://pms.uniontech.com/bug-view-251843.html

…ent naming

- Add std::unique + erase after sorting in getBlankFileIndex() to remove duplicate index numbers
- Prevent newly created documents from being stuck with the same "Untitled N" name when tabs with duplicate titles are dragged between windows

修复(editor): 对空白标签索引去重以修复新文档命名错误

- 在 getBlankFileIndex() 的排序后增加 std::unique + erase 去除重复的索引编号
- 修复跨窗口拖入同名"未命名文档"标签后,新建文档名称始终为同一编号的问题

Log: 修复跨窗口拖拽标签导致新文档命名计数器异常的 bug
Bug: https://pms.uniontech.com/bug-view-251843.html

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @pppanghu77, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

这段代码是对 getBlankFileIndex() 函数的修改,主要目的是在计算空白文件索引前去除重复的索引值。以下是我的审查意见:

语法逻辑

  • 语法正确,逻辑清晰。
  • 添加的注释解释了去除重复项的原因,即防止具有相同"Untitled N"名称的标签页在窗口间拖动时导致索引计算错误。
  • 原有的逻辑流程(排序、检查空列表)保持不变,修改仅增加了去重步骤。

代码质量

  • 代码质量良好,添加的注释提高了代码的可读性。
  • 使用了标准库算法 std::unique 进行去重,这是C++中的标准做法。
  • 去重操作放在排序之后是正确的,因为 std::unique 要求数列是有序的才能正确去除相邻的重复元素。

代码性能

  • 去除重复项的操作会增加一定的计算开销,但对于大多数应用场景,标签页数量不会太多,这个开销可以忽略不计。
  • 如果性能是关键考虑因素,可以考虑在插入时就避免重复,而不是在最后统一处理。

代码安全

  • 去除重复项可以防止潜在的索引计算错误,提高了代码的健壮性。
  • 使用 std::uniqueerase 的组合是安全的,不会导致内存泄漏或越界访问。

改进建议

  1. 考虑使用更明确的变量名,例如 tabIndexes 可以改为 blankFileIndices,以更准确地反映其用途。
  2. 如果这个函数频繁被调用且标签页数量可能很大,可以考虑使用集合(set)来存储索引,这样在插入时就能自动去重,避免最后的排序和去重操作。
  3. 可以添加断言来确保 tabIndexes 中的索引是有效的,例如在去重后添加一个范围检查。

总体而言,这是一个合理的改进,解决了潜在的标签页索引计算问题,代码质量良好,没有明显的安全问题。

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/widgets/window.cpp": [
        {
            "line": "    QString key = \"base/enable\";",
            "line_number": 390,
            "rule": "S106",
            "reason": "Var naming | 64f28539d9"
        }
    ]
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pppanghu77

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pppanghu77

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit fa2f750 into linuxdeepin:release/eagle Jun 9, 2026
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants